<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bom编辑</title>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="css/reset.css">
    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://at.alicdn.com/t/font_711817_dt555qoeeol.css">
    <link rel="stylesheet" href="css/common.css">
    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
    .right_content .panel-body {
        padding: 3%;
    }

    table {
        margin-top: 30px;
    }

    thead>tr>th {
        text-align: center;
    }

    table tr td {
        position: relative;
    }

    td>.hide_option {
        position: absolute;
        left: 19px;
        top: 40px;
        width: 196px;
        border: 1px solid #ccc;
        z-index: 66;
        background: #f9f9f9;
        border-top: none;
        display: none;
    }

    td>.hide_option>li {
        width: 100%;
        height: 34px;
        box-sizing: border-box;
        line-height: 22px;
        cursor: pointer;
        padding: 6px 12px;
    }

    td>.hide_option>li:hover {
        background: #eee;
    }
    </style>
</head>

<body>
    <!-- 头部导航 -->
    <nav class="navbar navbar-default navbar-fixed-top">
        <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">
                    <img alt="Brand" src="img/logo.png" class="img-responsive logo">
                    <span>仓库管理系统</span>
                </a>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="index.html">
                            <i class="icon iconfont">&#xea5b;</i>
                            <span>欢迎</span>
                        </a>
                    </li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">用户名 admin
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li>
                                <a href="#">个人资料</a>
                            </li>
                            <li>
                                <a href="#">Something else here</a>
                            </li>
                            <li role="separator" class="divider"></li>
                            <li>
                                <a href="#">退出登录</a>
                            </li>
                        </ul>
                    </li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container-fluid -->
    </nav>
    <!-- 主体部分 -->
    <div class="main">
        <div class="row main_content">
            <!-- 左侧菜单 -->
            <div class="col-xs-4 col-md-2 left_menu">
                <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                    <div class="panel panel-default menu_item">
                        <div class="panel-heading" role="tab" id="headingOne">
                            <h4 class="panel-title ">
                                <a class="menu_link clearfix" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                                    <span class="menu_title pull-left">库存管理</span>
                                    <span class="caret pull-right"></span>
                                </a>
                            </h4>
                        </div>
                        <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
                            <div class="panel-body">
                                <div class="list-group">
                                    <a href="#" class="list-group-item">
                                        库存管理
                                    </a>
                                    <a href="#" class="list-group-item">库存管理</a>
                                    <a href="#" class="list-group-item">库存管理</a>
                                    <a href="#" class="list-group-item">库存管理</a>
                                    <a href="#" class="list-group-item">库存管理</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel panel-default menu_item">
                        <div class="panel-heading" role="tab" id="headingTwo">
                            <h4 class="panel-title">
                                <a class="collapsed menu_link clearfix" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false"
                                    aria-controls="collapseTwo">
                                    <span class="menu_title pull-left">仓库管理</span>
                                    <span class="caret pull-right"></span>
                                </a>
                            </h4>
                        </div>
                        <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
                            <div class="panel-body">
                                <div class="list-group">
                                    <a href="#" class="list-group-item">
                                        货物入库
                                    </a>
                                    <a href="#" class="list-group-item">货物入库</a>
                                    <a href="#" class="list-group-item">货物入库</a>
                                    <a href="#" class="list-group-item">货物入库</a>
                                    <a href="#" class="list-group-item">货物入库</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel panel-default menu_item">
                        <div class="panel-heading" role="tab" id="headingThree">
                            <h4 class="panel-title">
                                <a class="collapsed menu_link clearfix" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false"
                                    aria-controls="collapseThree">
                                    <span class="menu_title pull-left">权限管理</span>
                                    <span class="caret pull-right"></span>
                                </a>
                            </h4>
                        </div>
                        <div id="collapseThree" class="panel-collapse collapse " role="tabpanel" aria-labelledby="headingThree">
                            <div class="panel-body">
                                <div class="list-group">
                                    <a href="#" class="list-group-item">
                                        人员管理
                                    </a>
                                    <a href="#" class="list-group-item">人员管理</a>
                                    <a href="#" class="list-group-item">人员管理</a>
                                    <a href="#" class="list-group-item">人员管理</a>
                                    <a href="#" class="list-group-item">人员管理</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel panel-default menu_item">
                        <div class="panel-heading" role="tab" id="headingFour">
                            <h4 class="panel-title ">
                                <a class="menu_link clearfix" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseFour" aria-expanded="true" aria-controls="collapseFour">
                                    <span class="menu_title pull-left">基础数据</span>
                                    <span class="caret pull-right"></span>
                                </a>
                            </h4>
                        </div>
                        <div id="collapseFour" class="panel-collapse collapse " role="tabpanel" aria-labelledby="headingFour">
                            <div class="panel-body">
                                <div class="list-group">
                                    <a href="#" class="list-group-item">
                                        供应商信息管理
                                    </a>
                                    <a href="#" class="list-group-item">客户信息管理</a>
                                    <a href="#" class="list-group-item">货物信息管理</a>
                                    <a href="#" class="list-group-item">仓库信息管理</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel panel-default menu_item">
                        <div class="panel-heading" role="tab" id="headingFive">
                            <h4 class="panel-title ">
                                <a class="menu_link clearfix" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseFive" aria-expanded="true" aria-controls="collapseFive">
                                    <span class="menu_title pull-left">人员管理</span>
                                    <span class="caret pull-right"></span>
                                </a>
                            </h4>
                        </div>
                        <div id="collapseFive" class="panel-collapse collapse " role="tabpanel" aria-labelledby="headingFive">
                            <div class="panel-body">
                                <div class="list-group">
                                    <a href="#" class="list-group-item">
                                        仓库管理员管理
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel panel-default menu_item">
                        <div class="panel-heading" role="tab" id="headingSix">
                            <h4 class="panel-title ">
                                <a class="menu_link clearfix" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseSix" aria-expanded="true" aria-controls="collapseSix">
                                    <span class="menu_title pull-left">系统维护</span>
                                    <span class="caret pull-right"></span>
                                </a>
                            </h4>
                        </div>
                        <div id="collapseSix" class="panel-collapse collapse " role="tabpanel" aria-labelledby="headingSix">
                            <div class="panel-body">
                                <div class="list-group">
                                    <a href="#" class="list-group-item">
                                        更改密码
                                    </a>
                                    <a href="#" class="list-group-item">系统日志</a>
                                    <a href="#" class="list-group-item">系统维护</a>
                                    <a href="#" class="list-group-item">系统维护</a>
                                    <a href="#" class="list-group-item">系统维护</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 右侧内容 -->
            <div class="col-xs-8 col-md-10 right_content">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <ol class="breadcrumb">
                            <li>Bom编辑/详情</li>
                        </ol>
                    </div>
                    <div class="panel-body">
                        <form class="form-inline">
                            <p>
                                <button id="addBom" class="btn btn-default form-control">Bom添加</button>
                            </p>
                            <div class="form-group">
                                <label>标题</label>
                                <input type="text" name="" class="form-control">
                            </div>
                            <button id="submit" class="btn btn-success pull-right">保存</button>
                            <table class="table table-bordered text-center table-hover table-striped">
                                    <thead>
                                        <th>名称</th>
                                        <th>数量(g)</th>
                                        <th>单价(元)</th>
                                        <th>金额(元)</th>
                                        <th>操作</th>
                                    </thead>
                                    <tbody class="modal_table">
                                        <!-- <tr>
                                            <td>
                                                <input id="title" class="form-control" type="text" name="" value="">
                                            </td>
                                            <td>
                                                <input id="num" class="form-control" type="num" name="" value="">
                                            </td>
                                            <td>
                                                <input readonly id="price" class="form-control" type="text" name="" value="">
                                            </td>
                                            <td>
                                                <input id="total" class="form-control" type="text" name="" value="">
                                            </td>
                                            <td>
                                                <button id="del" class="btn btn-danger btn-sm">删除</button>
                                            </td>
                                        </tr>-->
                                    </tbody>
                                </table>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="js/jquery-1.10.2.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="js/bootstrap.min.js"></script>
    <script type="text/javascript">
    var key = 0;
    $(function() {
        var data = [{
                title: "胶原蛋白肽",
                num: 10,
                unit_price: 12
            },
            {
                title: "速型奶昔",
                num: 11,
                unit_price: 11
            }
        ]
        var html = '';
        for (var i = 0; i < data.length; i++) {

            html += "<tr id='" + key + "'><td><input id='title" + key + "' name='title" + key + "' data='" + key + "'  type='text' onKeyup='getContent(this)' class='form-control match' value='" + data[i].title + "'/><ul class='hide_option'></ul></td><td><input class='form-control' type='number' value='" + data[i].num + "' id='num" + key + "' name='num" + key + "' onKeyup='getNum(this)' data-key='" + key + "' /></td><td><input name='unit_price" + key + "' id='unit_price" + key + "'  class='form-control' type='text' readonly value='" + data[i].unit_price + "' /></td><td><input class='form-control' type='text' id='total" + key + "' name='total" + key + "'  value='" + ((data[i].num * data[i].unit_price) / 1000) + "'/></td><td><button class='btn btn-danger' onclick='del(" + key + ")'>删除</button></td></tr>"
            key++;
        }
        $(".modal_table").html(html);
        /*bom添加*/
        $("#addBom").click(function(e) {
            e.preventDefault();
            var html = "";
            html = "<tr id='" + key + "'><td><input id='title" + key + "' name='title" + key + "' data='" + key + "' onKeyup='getContent(this)' type='text' class='form-control match' /><ul class='hide_option'></ul></td><td><input class='form-control' id='num" + key + "' name='num" + key + "' onKeyup='getNum(this)' type='number' data-key='" + key + "' /></td><td><input class='form-control' type='text' name='unit_price" + key + "' id='unit_price" + key + "' readonly  /></td><td><input id='total" + key + "' name='total" + key + "' class='form-control' type='text' /></td><td><button class='btn btn-danger' onclick='del(" + key + ")'>删除</button></td><input type='hidden'  id='price" + key + "'></tr>";
            key++;
            $(".modal_table").append(html);
        })

        /*点击保存*/
       /* $("#submit").click(function() {
            $.ajax({
                type: "POST",
                url: "https://jsonplaceholder.typicode.com/posts",
                data: {
                    title: $("#title").val(),
                    num: $("#num").val(),
                    price: $("#price").val(),
                    total: $("#total").val()
                },
                success: function(data) {
                    console.log(data)
                }
            })
        })*/
    })
    function getContent(obj) {
            var data = [
                {
                    title:"1111",
                    price:11111
                },
                {
                    title:"12",
                    price:111
                },
                {
                    title:"1221",
                    price:3
                }
            ];
            var kw = jQuery.trim($(obj).val());
            if (kw == "") {
                $(obj).next().hide().html("");
                return false;
            }
            var html = "";
            for (var i = 0; i < data.length; i++) {
                if (data[i].title.indexOf(kw) >= 0) {
                    html = html + "<li  onClick='getCon(this);' data-unit_price = " + data[i].price + ">" + data[i].title + "</li>"
                }
            }
            if (html != "") {
                $(obj).next().show().html(html);
            } else {
                $(obj).next().hide().html("");
            }
        }

        function getCon(obj) {
            var value = $(obj).text();
            var unit_price = $(obj).attr('data-unit_price');
            $(obj).parent().prev(".match").val(value);
            var key = $(obj).parent().prev(".match").attr('data');
            $('#unit_price' + key).val(unit_price);
            /*$('#price' + key).val(unit_price);*/
            var num = $('#num' + key).val();
            $('#total' + key).val(total(num, unit_price));
            $(obj).parent().hide()
        }
        function getNum(obj) {
            var num = $(obj).val();
            var key = $(obj).attr("data-key");
            var price = $('#unit_price' + key).val();
            $('#total' + key).val(total(num, price));
        }
        function total(num, price) {
            var total = 0;
            total = (num * price) / 1000;
            return total;
        }
        function del(id) {
            $('#' + id).remove();
        }
    </script>
</body>

</html>